package com.hangxintong.service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
* @Description
* @Author  Bz.Mr
* @Date   2021/1/15 14:20
*
*/
@Slf4j
@Service
public class MsgQueueService {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void SendSms(String phone,String code) {
        Map<String, String> sms = new HashMap<>();
        sms.put("phone", phone);
        sms.put("code", code);
        log.error("===>{}",sms);
        rabbitTemplate.convertAndSend("amq.topic","lianmeng.abcd", sms);

    }

    public void SendEventA(String phone,String code) {
        Map<String, String> sms = new HashMap<>();
        sms.put("phone", phone);
        sms.put("code", code);
        rabbitTemplate.convertAndSend("amq.topic","lianmeng.shenhe.eventA", sms);

    }

    public void sendLoginMsg(String phone,String code) throws JsonProcessingException {
        Map<String, String> sms = new HashMap<>();
        sms.put("phone", phone);
        sms.put("code", code);
        log.error("===>{}",sms);
        //转换器
        ObjectMapper mapper = new ObjectMapper();

        // 对象--json数据 //将对象转换成json
        String json=mapper.writeValueAsString(sms);
//        JSONObject parse = (JSONObject) JSON.parse(json);
        rabbitTemplate.convertAndSend("hxt-message.myQueue2", json);
//        rabbitTemplate.convertAndSend("amq.direct","hxt-message.loginMsg", sms);
        log.error("===55555555555>{}",sms);
    }
    /**
    * @Description
    * @Author  Bz.Mr
    * @Date   2021/1/14 15:51
    * 用户查看会费提醒
    */
    public void sendMembership(Map map) throws JsonProcessingException {
        //转换器
        ObjectMapper mapper = new ObjectMapper();
        // 对象--json数据 //将对象转换成json
        String json=mapper.writeValueAsString(map);
        rabbitTemplate.convertAndSend("hxt-message.myQueue0", json);
    }

}
